<?php
require('../private.php');
require_once(CONFIGPATH . 'wp-config.php');


function my_error($err="")
{
	if($err){
	$fh=fopen("/tmp/my_error.log", "w+");
	fputs($fh,$err);
	fclose($fh);
	}

}


// This current logic will actually take care of pinging for all posts in the system, for any blog,
// each time it is invoked. The trackbacks will be blog-specific.
// This doesn't really matter because the logic that sets
// _pingme in the first place is where all the per-blog relevant stuff happens, this just
// churns through and does all the work. And leaving it like this allows us to
// keep all of the ping code identical to WordPress. -jjb
/*
// Do pingbacks
while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
	$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
	pingback($ping->post_content, $ping->ID);
}
*/

// Do Enclosures
while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
	my_error("Doing eccloseures....".date(DATE_RFC822)."\n");
	$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");
	do_enclose($enclosure->post_content, $enclosure->ID);

}

// Do Trackbacks
$trackbacks = $wpdb->get_post_results("ID", "CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status != 'draft'");
if ( is_array($trackbacks) ) {
	foreach ( $trackbacks as $trackback ) {
		do_trackbacks($trackback->ID);
	}
}

?>
